package com.leo.train.business.controller.admin;

import com.leo.train.business.dto.CarriageQueryDto;
import com.leo.train.business.entity.Carriage;
import com.leo.train.business.service.CarriageService;
import com.leo.train.business.vo.CarriageQueryVo;
import com.leo.train.common.resp.CommonResp;
import com.leo.train.common.resp.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/carriage")
public class AdminCarriageController {
    @Autowired
    private CarriageService carriageService;
    /**
     * 新增
     * @param carriage
     */
    @PostMapping("/add")
    public CommonResp add(@RequestBody Carriage carriage) {
        carriageService.save(carriage);
        return new CommonResp<>();
    }

    /**
     * 修改
     * @param carriage
     */
    @PostMapping("/update")
    public CommonResp update(@RequestBody Carriage carriage) {
        carriageService.save(carriage);
        return new CommonResp<>();
    }

    /**
     * 删除
     * @param map
     */
    @PostMapping("/delete")
    public CommonResp delete(@RequestBody Map<String,Long> map) {
        Long id = map.get("id");
        carriageService.deleteById(id);
        return new CommonResp<>();
    }

    /**
     * 查询车厢列表
     * @param carriageQueryDto
     */
    @GetMapping("/list")
    public CommonResp<PageResult<CarriageQueryVo>> list(CarriageQueryDto carriageQueryDto) {
        PageResult<CarriageQueryVo> list = carriageService.list(carriageQueryDto);
        return new CommonResp<>(list);
    }

    /**
     * 查询车厢详情
     * @param id
     */
    @GetMapping("/detail")
    public CommonResp<CarriageQueryVo> deatail(@RequestParam Long id) {
        CarriageQueryVo detail = carriageService.detail(id);
        return new CommonResp<>(detail);
    }
}
